<?php

require_once './library/Zend/Db/Table/Abstract.php';

//require_once './library/Table.php';

class TableUtilisateurDashboard extends Zend_Db_Table_Abstract
{

    protected $_name;
    protected $_primary;
    protected $_db;
    protected $_registery;
    private $_select;

    protected function _setup()
    {
        $this->_name = 'utilisateur_dashboard';
        $this->_registry = Zend_Registry::getInstance();
        $this->_db = $this->_registry->get('adapter');
        parent::_setup();
    }

    public function getNbModuleDashboard($idUser, $idDashboard)
    {
        $select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
        $select->setIntegrityCheck(false)
                ->where('utilisateur_dashboard.IdUtilisateur = ?', $idUser)
                ->where('utilisateur_dashboard.IdDashboard = ?', $idDashboard);
        $rowset = $this->fetchAll($select);
        $count = 0;
        foreach ($rowset as $row)
        {
            $count++;
        }
        return $count;
    }

    public function ajouterModuleDashboard($idUser, $idDashboard)
    {
        $data = array(
            'IdUtilisateur' => $idUser,
            'IdDashboard' => $idDashboard
        );
        $this->insert($data);
    }

    public function retirerModuleDashboard($idUser, $idDashboard)
    {
        //$where = $this->getAdapter()->quoteInto("idUtilisateur = ? ", $idUser);
        $this->delete(array("IdUtilisateur = ? " => $idUser, "IdDashboard = ? " => $idDashboard));
    }

    public function getListeDashboardModule()
    {
        $select = $this->select();
        $row = $this->fetchAll($select);
        return $row;
    }

}
?>
